package com.codingvip.dynamic;

/**
 * @Author Tony.Han
 * @Created at 2020/4/5 10:04 下午
 * Desc:
 */
public class FindSquare {

    public int[] FindSquare(int[][] grid) {

        int m = grid.length, n = grid[0].length;
        int[] result = new int[3];
        int indexX;
        int indexY;
        int minValue=0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] == 1) {
                    grid[i][j] = 0;
                } else {
                    if (i == 0 || j == 0) {
                        grid[i][j] = 1;
                    } else {
                        grid[i][j] = minValue(grid, i, j) + 1;
                    }

                    if (grid[i][j] > minValue) {
                        minValue = grid[i][j];
                    }
                }
            }
        }
        return result;
    }

    private int minValue(int[][] grid, int i, int j) {

        return Math.min(Math.min(grid[i - 1][j], grid[i][j - 1]), grid[i - 1][j - 1]);
    }

}
